<template>
    <div>
        <el-table :data="page.records" @selection-change="handleSelectionChange" style="width: 1450px">
            <el-table-column type="selection" width="50" />
            <el-table-column prop="barCode" label="条码" width="140" />
            <el-table-column prop="categoryName" label="类别" width="170" />
            <el-table-column prop="color" label="颜色" width="320" />
            <el-table-column prop="commodityUnit" label="单位" width="170" />
            <el-table-column prop="materialName" label="名称" width="84" />
            <el-table-column prop="mfrs" label="扩展信息" width="82" />
            <el-table-column prop="model" label="型号" width="82" />
            <el-table-column prop="standard" label="规格" width="82" />
            <el-table-column prop="totalOperNumber" label="库存" width="82" />
        </el-table>
        <el-pagination v-model:page-size="page.size" v-model:current-page="page.current" @current-change="handleCurrentChange"
      @size-change="handleSizeChange" :page-sizes="[2, 4, 8, 10]" layout="total, sizes, prev, pager, next, jumper"
      :total="page.total" background style="margin-top:20px;">
    </el-pagination>
        <el-button type="primary" @click="saveSelectedItems">保存</el-button>
    </div>
  </template>
  
  <script lang="ts" setup>
  import { ref, defineEmits,defineProps } from 'vue';
  import request from '@/api/request';
  import { ElMessage } from 'element-plus';
  
  let emit = defineEmits(['saveSaleinorder', 'closeDialog']); // 添加 closeDialog 事件
  let props = defineProps(['currentDepotId'])
  console.log(props.currentDepotId);
  
  const page = ref({
    current: 1,
    size: 10,
    total: 0,
    records: []
  });
  
  
  const handleCurrentChange = (val) => {
    page.value.current = val;
    loadMenus();
  };
  
  const handleSizeChange = (val) => {
    page.value.size = val;
    page.value.current = 1;
    loadMenus();
  };
  
  const loadMenus = () => {
    request({
        url: '/erpmaterialinventory/findByPage',
        method: "get",
        params: {
            current: page.value.current,
            size: page.value.size,
            depotId:props.currentDepotId
        }
    }).then(res => {
        page.value.records = res.data.records;
        page.value.total = res.data.total;
    }).catch(err => {
        ElMessage.error('加载数据失败');
    });
  };
  
  
  const selectedItems = ref([]);
  
  const saveSelectedItems = () => {  
    if (selectedItems.value.length === 0) {  
      ElMessage.warning('请至少选择一个商品');  
      return;  
    }  
    emit('saveSaleinorder', selectedItems.value);  
    selectedItems.value = []; // 清空选中的项，以便下次选择  
  };
  
  
  const handleSelectionChange = (val) => {  
    selectedItems.value = val;  
   
    
  }; 
  loadMenus();
  </script>
  